import { message } from 'antd'
import { getJSON } from '@sunl-fe/dataservice'

export const request = (api, param, headers = {}, method, responseType = 'json') => {
    const [url, type = 'form'] = api.split('|').reverse()
    if (type === 'json') {
        param = JSON.stringify(param)
        if (method === undefined) {
            method = 'POST'
        }
    }
    return getJSON(
        url,
        param,
        { method: method || 'POST' },
    ).catch(err => {
        message.error(`${err.msg || err}`)
        console.error(`👉${err.msg || err}👈`)
        throw err // !!!抛出异常，使 saga fail
    })
}

export default {
    request,
}
